package com.hcbd.tdwt.base.bd;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.widget.Toast;

import androidx.core.app.ActivityCompat;

import com.hcbd.tdwt.base.BdManager;
import com.hcbd.tdwt.base.BeidouBoxParams;
import com.pangu.bdsdk2021.bluetooth.BluetoothManage;
import com.hcbd.tdwt.ui.xingyu.activity.SearchBluetoothActivity_;
import com.hcbd.tdwt.ui.xingyu.dialog.OldProtocolDialog;

public abstract class BdSendBase {
    public boolean enableRD = false;
    public boolean enableRN = false;
    protected final String[] PERMISSIONS_BLUETOOTH = {
            Manifest.permission.BLUETOOTH_SCAN,
            Manifest.permission.BLUETOOTH_ADVERTISE,
            Manifest.permission.BLUETOOTH_CONNECT
    };
    private OldProtocolDialog oldProtocolDialog;
    public void showOldProtocolDialog(Activity activity,String content,OldProtocolDialog.OnCloseListener onCloseListener) {
        if (oldProtocolDialog == null) {
            oldProtocolDialog = new OldProtocolDialog();
        }
        if (oldProtocolDialog.isAdded()) return;
        oldProtocolDialog.setData(activity, content,onCloseListener);
        oldProtocolDialog.show(activity.getFragmentManager(), "");
    }
    public void open(Activity activity,int code){
        if (!BluetoothManage.getInstance().isEnable()) {
            Toast.makeText(activity,"请打开蓝牙！",Toast.LENGTH_SHORT).show();
            return;
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
            if(ActivityCompat.checkSelfPermission(activity, Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED){
                ActivityCompat.requestPermissions(activity, PERMISSIONS_BLUETOOTH, 1001);
                return;
            }
        }
        Intent intent = new Intent();
        intent.setClass(activity, SearchBluetoothActivity_.class);
        activity.startActivityForResult(intent, code);
    }
    public void close(Activity activity){
        if(BeidouBoxParams.isBoxConnectNormal){
            BluetoothManage.getInstance().disConnect();
            BdManager.getInstance().onDisconnect();
        }
    }
    abstract public void sendMsg(String number, int frePoint, int mode, String content);
    abstract public void getICInfo();
    public void sendEPQInfo(String TheReceivingPartyID,int EmergencySigns, int ElevationValue, int SearchAndRescueType){

    }
    public void initBle(){
        BeidouBoxParams.isBoxConnectNormal = true;
    }
}
